// pages/staff_record/staff_record.js
const App = getApp();
const Api = require('../../utils/api.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    name: '',
    reported: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    let userInfo = wx.getStorageSync("userInfo")
    that.setData({
        myid:userInfo.id,
        id: options.id,
        name: options.name
    }, () => {
      that.getListTemperature()
    })
  },

  getListTemperature() {
    let _this = this;
    let data = {
      uid: _this.data.id
    };
    Api.fetch('listTemperature', data)
      .then(res => {
        if (res.data.code == 1) {
          _this.setData({
            list: res.data.data,
          })
        }
      })
      .catch(e => {
        console.log(e);
      })
  },

  reportedHandle(e) {
    let that = this
    console.log(e.currentTarget.dataset.uid)
    that.setData({
      reported: !that.data.reported,
      // currentNickname: e.currentTarget.dataset.nickname,
      // currentUid: e.currentTarget.dataset.uid,
    })
  },

  // 上报体温
  formSubmit: function (e) {
    let _this = this;
    let info = e.detail.value;
    if (!info.temperature) {
      wx.showToast({
        title: '请输入体温',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    let data = {
      'uid': _this.data.id,
      'temperature': info.temperature,
    };
    Api.fetch('upTemperature', data)
      .then(res => {
        console.log(res.data);
        if (res.data.code == 1) {
          _this.setData({
            reported: false,
          }),
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          setTimeout(() => {
              _this.getListTemperature()
          }, 1500)
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }
      })
      .catch(e => {
        console.log(e);
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})